import { Controller, Get, Post, Body, Query, UseGuards } from '@nestjs/common';
import { RoleService } from './role.service';
import { Role } from '../../entities/role.entity';
import { ApiTags, ApiQuery, ApiProperty, ApiOperation } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { Roles } from '../roles/roles.decorator';
import { RoleGuard } from '../roles/roles.guard';
export class QueryDt {
    @ApiProperty({
        description: '角色名称',
        required: false
    })
    username: string;

    @ApiProperty({
        description: '当前页数',
        type: 'text',
        required: false
    })
    currentPage: number;

    @ApiProperty({
        description: '当前页码数',
        type: 'text',
        required: false
    })
    pageSize: number;

    @ApiProperty({
        description: '按创建时间排序',
        type: 'text',
        required: false
    })
    order_by_update: string
}

@ApiTags('角色信息')
@Controller('role')
export class RoleController {
    constructor(private roleService: RoleService) { }

    @Get('/get')
    // @UseGuards(AuthGuard())
    @ApiOperation({ summary: '获取角色列表' })
    getAllUsers(@Query() data: QueryDt) {
        return this.roleService.getAllRoles(data)
    }

    @Get('/get/ById')
    @ApiOperation({ summary: '获取角色' })
    @ApiQuery({ name: 'id', description: '角色id', required: true })
    getUser(@Query('id') id) {
        return this.roleService.findRoleById(+id)
    }
    @Post('/add')
    @UseGuards(AuthGuard(), RoleGuard)
    @Roles('F0020')
    @ApiOperation({ summary: '创建角色' })
    public add(@Body() user: Role) {
        return this.roleService.addOrUpdateRole(user)
    }
    @Post('/edit')
    @ApiOperation({ summary: '编辑角色' })
    @UseGuards(AuthGuard(), RoleGuard)
    @Roles('F0021')
    public editUser(@Body() user: Role) {
        return this.roleService.addOrUpdateRole(user)
    }
    @Post('/delete')
    @ApiOperation({ summary: '删除角色' })
    @ApiQuery({ name: 'id', description: '角色id', required: true })
    @UseGuards(AuthGuard(), RoleGuard)
    @Roles('F0022')
    public delete(@Query('id') id: number) {
        return this.roleService.delete(id)
    }
    @Post('/menu')
    @ApiOperation({ summary: '权限菜单' })
    @UseGuards(AuthGuard(), RoleGuard)
    @Roles('F0023')
    public menu() {
        return this.roleService.getMenu()
    }
}